package cn.kgc.bilibili.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;


public abstract class UserAlimessage {
    /**
     * 找回密码
     * 修改密码
     * 换绑手机
     * @param phone
     * @return 验证码
     */
    public static Integer Message(String phone){
        int code = (int) ((Math.random()*9+1)*100000);
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4Fjx6DhfWYS883yGoUTY", "w060ucohXsGMK9AsrkhEcJN3wztESI");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "机器人熊二");
        request.putQueryParameter("TemplateCode", "SMS_175539436");
        request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return code;
    }
}
